package sz.szsmk.citizencard.ui.newversion.fragment.adapter

import android.content.Context
import android.graphics.Rect
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.layout_homeusermodule.view.*
import sz.szsmk.citizencard.R
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo
import sz.szsmk.citizencard.util.GlideRoundTransform
import sz.szsmk.citizencard.util.JumpThirdView
import sz.szsmk.citizencard.util.JumpUtils

/**
 *  author : hyt
 *  date : 2020/10/28
 *  description :
 */
class HomeFinanceAdapter(var mContext: Context? = null)
    : RecyclerView.Adapter<HomeFinanceAdapter.HomeFinanceHolder>(){

    var datas = mutableListOf<AdInfo>()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
            HomeFinanceHolder(LayoutInflater.from(mContext)
                    .inflate(R.layout.layout_financeitem, parent, false))

    override fun onBindViewHolder(holder: HomeFinanceHolder, position: Int) {
        var bean = datas[position]
            Glide.with(mContext).load(bean.resource_url)
                .transform(GlideRoundTransform(mContext))
                .into(holder.itemView.iv_img)

        holder.itemView.tv_title.text = bean.resource_name
        holder.itemView.setOnClickListener { _ ->
            JumpThirdView.baseToJumpView(mContext,bean.link_url,bean.sys_label, bean.need_header,"")
        }
    }

    override fun getItemCount() = datas.size

    fun addDatas(datas: List<AdInfo>){
        this.datas.clear()
        this.datas.addAll(datas)
        notifyDataSetChanged()
    }


    class HomeFinanceHolder(var view: View) : RecyclerView.ViewHolder(view)
}
//分割线  间距
class SpaceItemDecoration(var mSpace:Int) : RecyclerView.ItemDecoration() {

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        super.getItemOffsets(outRect, view!!, parent, state!!)
        outRect.left = mSpace
        outRect.right = mSpace
        outRect.bottom = mSpace
        outRect.top = mSpace
    }
}